package com.sc.byahi.user.client;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.History;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.TextBox;
import com.sc.byahi.user.client.components.HistoryTokens;

public class ProfileIDSearchView extends Composite {
	private final Label lblProfileId = new Label("Profile ID");
	private final TextBox txtProfileId = new TextBox();
	private final Button btnSearchProfileID = new Button("Search profile");

	public ProfileIDSearchView() {
		FlexTable tab = new FlexTable();
		tab.setStyleName("my-form");
		tab.setStylePrimaryName("my-form");
		initWidget(tab);
		setStyleName("profile-search-top");

		FlowPanel hp = new FlowPanel();
		hp.add(txtProfileId);
		hp.add(btnSearchProfileID);

		int row = 0;
		tab.setWidget(row++, 0, lblProfileId);
		tab.setWidget(row++, 0, hp);

		btnSearchProfileID.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				final String id = txtProfileId.getText().trim();
				if (!"".equals(id)) {
					History.newItem(HistoryTokens.ID_SEARCH_RESULT + ":"+id, true);// so that token change works when user clicks search again
				}
			}
		});
	}
}
